import java.util.ArrayList;
import java.util.List;

public class JdkQueue {
    public static void main(String[] args) {

        //测试队列
        System.out.println("测试队列：");
        Queue queue = new Queue();
        queue.in(1);
        queue.in(2);
        queue.in(3);
        System.out.println("出队元素为：" + queue.out());
        System.out.println("出队元素为：" + queue.out());
        queue.in(4);
        System.out.println("出队元素为：" + queue.out());
        System.out.println("出队元素为：" + queue.out());
        queue.in(5);
        System.out.println("出队元素为：" + queue.out());

    }
}

//使用集合定义一个队列
class Queue {
    List<Integer> list = new ArrayList<Integer>();
    int index = 0;  //下标

    //入队
    public void in(int n) {
        list.add(n);
        index++;
    }

    //出队
    public int out() {
        if (!list.isEmpty()) {
            index--;
            return list.remove(0);
        }
        return -1;
    }

}

